import React from "react"

import http from "../helper/request"
import {
	IArtificialDepositList,
	IGetArtificialDepositListParams,
	ILevelLinkResponseItem,
	ILevelListQueryParams,
	IMemberDepositRecordList,
	IMemberRebateDetailList,
	IMemberRebateDetailParams,
	IMemberRebateRecordList,
	IMemberRebateSummaryList,
	IMemberTeamBillList,
	IMemberTeamBillParams,
	IMemberTeamDetailsPageParams,
	IMemberTeamListPageParams,
	IMemberWithdrawRecordList,
	IOptPage,
	IOutLineInfoParams,
	IOutLineInfoResponse,
	IProxyDepositRecordItemResponse,
	IProxyDepositRecordListParams,
	IProxyDepositSummaryResponse,
	IProxyWithdrawItemResponse,
	IProxyWithdrawListParams,
	IProxyWithdrawSummary,
	IQueryMemberDepositRecordParams,
	IQueryMemberRebateRecordParams,
	IQueryMemberWithdrawRecordParams
} from "./types"

const useFundsApi = () => {
	const { useState } = React
	const [loading, setLoading] = useState(false)

	async function generalHttp<T>(url: string, body: object | undefined) {
		setLoading(true)
		const ret = await http.post<T>(url, body)
		setLoading(false)
		return ret
	}

	async function generalGet<T>(url: string, body: object | undefined) {
		setLoading(true)
		const ret = await http.get<T>(url, body)
		setLoading(false)
		return ret
	}

	const queryMemberDepositRecordList = async (params: IQueryMemberDepositRecordParams) => {
		//会员存款记录
		const ret = await generalHttp<IMemberDepositRecordList>("/member/deposit/record/list", params)
		return ret
	}

	const getMemberWithdrawOnlinePayRecordList = async (params: IQueryMemberWithdrawRecordParams) => {
		//会员取款记录
		const ret = await generalHttp<IMemberWithdrawRecordList>("/memberFundsRecords/withdraw/onlinePay/record/list", params)
		return ret
	}

	const getArtificialDepositList = async (params: IGetArtificialDepositListParams) => {
		//后台存取款记录
		const ret = await generalHttp<IArtificialDepositList>("/artificial/deposit/withdraw/list", params)
		return ret
	}

	const getProxyDepositRecordList = (body: IProxyDepositRecordListParams) => {
		const ret = generalHttp<Business.TableResourceType<IProxyDepositRecordItemResponse, IProxyDepositSummaryResponse>>(
			"/proxyFundsRecords/proxy/deposit/record/list",
			body
		)

		return ret
	}

	const getProxyWithdrawRecordList = (body: IProxyWithdrawListParams) => {
		const ret = generalHttp<Business.TableResourceType<IProxyWithdrawItemResponse, IProxyWithdrawSummary>>(
			"/proxyFundsRecords/withdraw/record/list",
			body
		)
		return ret
	}
	const getMemberRebateReportList = async (params: IQueryMemberRebateRecordParams) => {
		const ret = await generalHttp<IMemberRebateRecordList>("/report/memberRebate/list", params)
		return ret
	}

	const proxyLevelLink = async (params: ILevelListQueryParams) =>
		await generalHttp<ILevelLinkResponseItem>("/report/proxyTree/levelLink", params)

	const getAllMemberList = async (params: any) => await generalHttp("/report/proxyTree/getMemberMainInfo", params)
	const getAllOptPages = async () => await generalGet<IOptPage[]>("/funds/accountOptLog/getAllOptPages", undefined)
	const getMemberRebateDetailList = async (params: IMemberRebateDetailParams) => {
		//会员返水详情
		const ret = await generalHttp<IMemberRebateDetailList>("/report/memberRebate/detailList", params)
		return ret
	}
	const getMemberRebateDetailListSummary = async (params: IMemberRebateDetailParams) => {
		//会员返水详情
		const ret = await generalHttp<IMemberRebateSummaryList>("/report/memberRebate/detailSummary", params)
		return ret
	}

	const proxyTeamBillPeriod = async (params: IMemberTeamBillParams) => {
		const ret = await generalHttp<IMemberTeamBillList>("/report/proxyTeamBill/period/list", params)
		return ret
	}

	const memberTeamBillList = async (params: IMemberTeamListPageParams) => {
		const ret = await generalHttp<any>("/report/memberTeamBill/listPage", params)
		return ret
	}

	const memberTeamBillDetail = async (params: IMemberTeamDetailsPageParams) => {
		const ret = await generalHttp<any>("/report/memberTeamBill/detail", params)
		return ret
	}

	const memberTeamBillExport = async (params: IMemberTeamDetailsPageParams) => {
		const ret = await generalHttp<any>("/report/memberTeamBill/export", params)
		return ret
	}

	const getOutlineInfo = async (params: IOutLineInfoParams) =>
		await generalGet<IOutLineInfoResponse>("/member/outlineInfo", params)

	return {
		queryMemberDepositRecordList,
		getMemberWithdrawOnlinePayRecordList,
		generalHttp,
		getProxyDepositRecordList,
		getProxyWithdrawRecordList,
		loading,
		getMemberRebateReportList,
		proxyLevelLink,
		getAllMemberList,
		getAllOptPages,
		getOutlineInfo,
		getMemberRebateDetailList,
		getMemberRebateDetailListSummary,
		proxyTeamBillPeriod,
		memberTeamBillList,
		memberTeamBillDetail,
		memberTeamBillExport,
		getArtificialDepositList
	}
}

export default useFundsApi
